////////////////////////////////////////////////////////////////////////////////
//
//  nino
//
////////////////////////////////////////////////////////////////////////////////


package ochart.utils.logging
{
	import flash.events.EventDispatcher;
	
	import ochart.utils.logging.appender.Appender;
	import ochart.utils.logging.appender.TraceAppender;
	
	public class LoggerManager extends EventDispatcher
	{
		private static var _instance:LoggerManager = null;
		
		public static function get instance():LoggerManager
		{
			if(!_instance)
			{
				_instance = new LoggerManager();
			}
			return _instance;
		}
		
		public var levelThreshold:Level = null;
		public var logCountThreshold:int = 0;
		private var logRepository:LogRepository = null;
		private var appenderArray:Array = [];
		
		public function LoggerManager()
		{
			levelThreshold = Level.DEBUG;
			logCountThreshold = 1000;
			logRepository = LogRepository.instance;
			
			var traceAppender:TraceAppender = new TraceAppender();
			appenderArray.push(traceAppender);
		}
		
		public function add(log:Log):Boolean
		{
			if(!log)
			{
				return false;
			}
			if(!log.level.isGreaterOrEqual(this.levelThreshold))
			{
				return false;
			}
			logRepository.add(log);
			for each(var appender:Appender in appenderArray)
			{
				appender.append(log);
			}
			return true;
		}
	}
}